import Http from "../utils/http";
import {formdata} from '../utils/util'
import cache from "../enum/cache"
import Base from "./base"

class Information extends Base {
  // 获取个人信息
  static async getMyRoles(data) {
    const res = await Http.request({
        url: `/app/getInfo`,
        data,
        method: 'GET'
    })
    // 判断是否包含专家角色 expert
    let role = res.roles.includes('expert') ? 'expert' : 'common'
    // 存储角色和用户信息
    wx.setStorageSync(cache.USER_ROLES, role)
    wx.setStorageSync(cache.USER_INFO, res.profProf)
    wx.setStorageSync(cache.COMMON_INFO, res.user)
    return res
  }
  // 获取个人信息
  static async getMyInfo() {
    const res = await Http.request({
        url: `/expert/getAppExpertInfo`,
        method: 'GET'
    })
    return res
  }
  // 获取单位options
  static getUnitList(data) {
    return Http.request({
        url: `/expert/unitList`,
        data,
        method: 'GET'
    })
  }
  // 获取职称options
  static getLevelList(data) {
    return Http.request({
        url: `/system/dict/data/type/prof_title`,
        data,
        method: 'GET'
    })
  }
  // 获取专业options
  static getMajoryList(data) {
    return Http.request({
        url: `/expert/areaTreeList`,
        data,
        method: 'GET'
    })
  }
  // 个人信息
  static updateMyInfo(data) {
    return Http.request({
        url: `/expert/updateExpert`,
        data,
        method: 'POST'
    })
  }
  // 获取繁忙原因 
  static getBusyStatus() {
    return Http.request({
        url: `/system/dict/data/type/expert_status`,
        method: 'GET'
    })
  }
  // 我的状态
  async getMyStatus() {
    // 先判断是否有更多数据
    if(!this.hasMoreData) {
      return this.data
    }
    const list = await Http.request({
        url: `/expert/status/list`,
        data: {
          pageNum: this.pageNum, 
          pageSize: this.pageSize,
        },
        method: 'GET'
    })
    this.data = this.data.concat(list.rows)
    this.hasMoreData = !(this.pageNum === list.pages)
    this.pageNum ++
    return this.data
  }
  // 新增状态
  static addStatus(data) {
    return Http.request({
        url: `/expert/status`,
        data,
        method: 'POST'
    })
  }
  // 查询状态
  static getStatus() {
    return Http.request({
        url: `/expert/status/getIsbusy`,
        method: 'GET'
    })
  }
  // 删除状态
  static delectStatus(id) {
    return Http.request({
        url: `/expert/status/${id}`,
        method: 'DELETE'
    })
  }
  // 参与项目
  static getMyProject(data) {
    return Http.request({
        url: `/projectManage/selectProjectExpertList`,
        data: formdata(data),
        method: 'POST',
        header: {
          'content-type': 'multipart/form-data; boundary=XXX'
        },
    })
  }
  // 我的消息
  async getMyMessage(type=null) {
    // 先判断是否有更多数据
    if(!this.hasMoreData) {
      return this.data
    }
    const list = await Http.request({
        url: `/message/selectMailReceiveList`,
        data: formdata({
          pageNum: this.pageNum, 
          pageSize: this.pageSize,
          mailType: type
        }),
        method: 'POST',
        header: {
          'content-type': 'multipart/form-data; boundary=XXX'
        },
    })
    this.data = this.data.concat(list.rows)
    this.hasMoreData = !(this.pageNum === list.pages)
    this.pageNum ++
    return this.data
  }
  // 修改专家参会状态
  static updateExpertsParticipants(data) {
    return Http.request({
        url: `/message/updateExpertsParticipants`,
        data,
        method: 'POST'
    })
  }
  // 修改审核状态
  static updateCheckStatus(data) {
    return Http.request({
        url: `/projectManage/selectMailProjectInfo`,
        data,
        method: 'POST'
    })
  }
  // 头像上传
  static uploadAvatar(data) {
    console.log(data);
    return Http.request({
      url: `/minio/UploadByExpertId`,
      filePath: data,
      name:'file',
      data: formdata({
        bucketName: 'touxiang',
        expertId: 'f165f42f5b3149c6bddd2dbee8c3d655',
        
      }),
      header: {
        'content-type': 'multipart/form-data; boundary=XXX'
      },
      method: 'POST'
  })
  }
}

export default Information